package pATT.bNEdit.gui;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.util.Enumeration;
import java.util.Observable;
import java.util.Observer;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.event.InternalFrameEvent;

import pATT.bNEdit.base.Nodo;
import pATT.bNEdit.base.RedBayes;



/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author Martin Blech && Luciana Zavaleta
 * @version 1.0
 */

public class BNEditInternalFrame extends JInternalFrame implements Observer
{
  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
public static final int MODE_SELECT = 0;
  public static final int MODE_NODE = 1;
  public static final int MODE_ARC = 2;


  private BNEditMainFrame mainFrame;
  private RedBayes bayesianNetwork;
  private String fileName;
  private NetView netView;
  private boolean changed = false;

  private int mode = MODE_SELECT;
  private Object selected = null;

  CardLayout cardManager=new CardLayout();

  JPanel contentPane;
  JPanel tablesPanel=new JPanel();

  JToolBar toolBar = new JToolBar();
  JToolBar toolbarNodeProperties = new JToolBar();

  ButtonGroup buttonGroupToolSelection = new ButtonGroup();
  ButtonGroup buttonGroupRun = new ButtonGroup();

  JToggleButton buttonPropSumNormal=new JToggleButton();
  JToggleButton buttonPropMaxNormal=new JToggleButton();
  JToggleButton buttonPropSumRetract=new JToggleButton();
  JToggleButton buttonPropMaxRetract=new JToggleButton();
  JToggleButton buttonSelect = new JToggleButton();
  JToggleButton buttonCreateVar = new JToggleButton();
  JToggleButton buttonCreateLink = new JToggleButton();
  JToggleButton toggleNodeProperties = new JToggleButton();
  public JToggleButton buttonRun=new JToggleButton();

  JScrollPane scrollPane;

  RunPanel runPanel=new RunPanel();
  JButton buttonNetworkProperties = new JButton();
  JButton buttonInicNet=new JButton();
  JButton buttonDelete = new JButton();
  JButton buttonAddExpTable = new JButton();
  JButton buttonAdaptation = new JButton();
  JButton buttonMonitor = new JButton();
  JButton buttonDelExpTable = new JButton();

  NodePropertiesPanel nodePropertiesPanel = new NodePropertiesPanel();
  ExperiencePanel experienceTable=new ExperiencePanel();


  public BNEditInternalFrame(RedBayes bayesianNetwork,
                             String fileName,
                             BNEditMainFrame mainFrame) {
    this.bayesianNetwork = bayesianNetwork;
    bayesianNetwork.addObserver(this);
    this.fileName = fileName;
    this.mainFrame = mainFrame;
    this.setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
    bnInit();
  }

  //Component initialization
  private void jbInit() throws Exception {
    netView=new NetView();
    netView.setBNEditInternalFrame(this);
    scrollPane = new JScrollPane(netView);
    runPanel.setInternalFrame(this);

    this.setFrameIcon(ResourceManager.getIcon("fileIcon.gif"));
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(new BorderLayout());
    this.setSize(new Dimension(550,350));
    this.addInternalFrameListener(new BNEditInternalFrame_this_internalFrameAdapter(this));
    this.setTitle(bayesianNetwork.getNombre());

    buttonNetworkProperties.setAlignmentY((float) 0.5);
    buttonNetworkProperties.setToolTipText("Network properties");
    buttonNetworkProperties.setIcon(ResourceManager.getIcon("netprop.gif"));
    buttonNetworkProperties.addActionListener(new BNEditInternalFrame_buttonNetworkProperties_actionAdapter(this));

    buttonSelect.setSelected(true);
    buttonSelect.setToolTipText("Select tool");
    buttonSelect.setIcon(ResourceManager.getIcon("arrow.gif"));
    buttonSelect.addActionListener(new BNEditInternalFrame_buttonSelect_actionAdapter(this));

    buttonCreateVar.setToolTipText("Variable tool");
    buttonCreateVar.setIcon(ResourceManager.getIcon("dnode.gif"));
    buttonCreateVar.addActionListener(new BNEditInternalFrame_buttonCreateVar_actionAdapter(this));

    buttonCreateLink.setToolTipText("Link tool");
    buttonCreateLink.setIcon(ResourceManager.getIcon("arrow_constraint.gif"));
    buttonCreateLink.addActionListener(new BNEditInternalFrame_buttonCreateLink_actionAdapter(this));

    buttonRun.setToolTipText("Run");
    buttonRun.setIcon(ResourceManager.getIcon("run.gif"));
    buttonRun.addItemListener(new BNEditInternalFrame_buttonRun_itemAdapter(this));

    buttonInicNet.setToolTipText("InitializeNetwork");
    buttonInicNet.setIcon(ResourceManager.getIcon("initialize.gif"));
    buttonInicNet.addActionListener(new BNEditInternalFrame_buttonInicNet_actionAdapter(this));

    buttonPropSumNormal.setToolTipText("Sum-propagate normal");
    buttonPropSumNormal.setIcon(ResourceManager.getIcon("propsumnormal.gif"));
    buttonPropSumNormal.addActionListener(new BNEditInternalFrame_buttonPropSumNormal_actionAdapter(this));

    buttonPropMaxNormal.setToolTipText("Max-propagate normal");
    buttonPropMaxNormal.setIcon(ResourceManager.getIcon("propmaxnormal.gif"));
    buttonPropMaxNormal.addActionListener(new BNEditInternalFrame_buttonPropMaxNormal_actionAdapter(this));

    buttonPropSumRetract.setToolTipText("Sum-propagate fast retract");
    buttonPropSumRetract.setIcon(ResourceManager.getIcon("propsumfastretract.gif"));
    buttonPropSumRetract.addActionListener(new BNEditInternalFrame_buttonPropSumRetract_actionAdapter(this));

    buttonPropMaxRetract.setToolTipText("Max-propagate fast retract");
    buttonPropMaxRetract.setIcon(ResourceManager.getIcon("propmaxfastretract.gif"));
    buttonPropMaxRetract.addActionListener(new BNEditInternalFrame_buttonPropMaxRetract_actionAdapter(this));

    toggleNodeProperties.setToolTipText("Node properties");
    toggleNodeProperties.setIcon(ResourceManager.getIcon("nodeproperties.gif"));
    toggleNodeProperties.addItemListener(new BNEditInternalFrame_toggleNodeProperties_itemAdapter(this));

    buttonDelete.setToolTipText("Delete node/arc");
    buttonDelete.setIcon(ResourceManager.getIcon("delete.gif"));
    buttonDelete.addActionListener(new BNEditInternalFrame_buttonDelete_actionAdapter(this));
    buttonDelete.setEnabled(false);

    buttonAddExpTable.setToolTipText("Add Experience Table");
    buttonAddExpTable.setIcon(ResourceManager.getIcon("tablewindow.gif"));
    buttonAddExpTable.addActionListener(new BNEditInternalFrame_buttonAddExpTable_actionAdapter(this));

    buttonAdaptation.setToolTipText("Adapt Tables");
    buttonAdaptation.setIcon(ResourceManager.getIcon("adaptation.gif"));
    buttonAdaptation.addActionListener(new BNEditInternalFrame_buttonAdaptation_actionAdapter(this));

    buttonMonitor.setToolTipText("Change to Monitor View");
    buttonMonitor.setIcon(ResourceManager.getIcon("monitors.gif"));
    buttonMonitor.addActionListener(new BNEditInternalFrame_buttonMonitor_actionAdapter(this));

    buttonDelExpTable.setToolTipText("Delete experience Table");
    buttonDelExpTable.setIcon(ResourceManager.getIcon("delExpTable.png"));
    buttonDelExpTable.addActionListener(new BNEditInternalFrame_buttonDelExpTable_actionAdapter(this));

    this.setClosable(true);
    this.setContentPane(contentPane);
    this.setIconifiable(true);
    this.setMaximizable(true);
    this.setNormalBounds(new Rectangle(10, 10, 600, 400));
    this.setResizable(true);
    this.setPreferredSize(new Dimension(640, 62));

    toolBar.add(buttonDelExpTable, null);
    toolBar.add(buttonAddExpTable, null);
    toolBar.addSeparator();
    toolBar.add(buttonNetworkProperties, null);
    toolBar.add(toggleNodeProperties, null);
    toolBar.addSeparator();
    toolBar.add(buttonSelect, null);
    toolBar.add(buttonCreateVar, null);
    toolBar.add(buttonCreateLink, null);
    toolBar.add(buttonDelete, null);
    toolBar.addSeparator();
    toolBar.add(buttonRun,null);
    toolBar.add(buttonInicNet,null);
    toolBar.add(buttonPropSumNormal,null);
    toolBar.add(buttonPropMaxNormal,null);
    toolBar.add(buttonPropSumRetract,null);
    toolBar.add(buttonPropMaxRetract,null);
    toolBar.add(buttonAdaptation, null);
    toolBar.add(buttonMonitor, null);

    buttonGroupToolSelection.add(buttonCreateLink);
    buttonGroupToolSelection.add(buttonCreateVar);
    buttonGroupToolSelection.add(buttonSelect);


    buttonGroupRun.add(buttonPropSumNormal);
    buttonGroupRun.add(buttonPropMaxNormal);
    buttonGroupRun.add(buttonPropSumRetract);
    buttonGroupRun.add(buttonPropMaxRetract);

    tablesPanel.setLayout(cardManager);
    tablesPanel.add(nodePropertiesPanel, ""+mainFrame.TABLE_PROB);
    tablesPanel.add(experienceTable, ""+mainFrame.TABLE_EXP);
    tablesPanel.setVisible(false);


    contentPane.add(toolBar, BorderLayout.NORTH);
    contentPane.add(tablesPanel, BorderLayout.WEST);
    contentPane.add(runPanel,  BorderLayout.SOUTH);
    contentPane.add(scrollPane,  BorderLayout.CENTER);

    nodePropertiesPanel.setBayesianNetwork(bayesianNetwork);
    nodePropertiesPanel.setCurrentNode(null);
    nodePropertiesPanel.setInternalFrame(this);
    nodePropertiesPanel.setVisible(false);

    experienceTable.setBayesianNetwork(bayesianNetwork);
    experienceTable.setCurrentNode(null);

    runPanel.setBayesianNetwork(bayesianNetwork);
    runPanel.setVisible(false);

    setVisibleRun(false);
  }

  /**
   * initializes the graph with the structure of the bayesian network
   */
  private void bnInit() {
    Enumeration varNamesEnum = bayesianNetwork.ListaVariables().elements();
    while (varNamesEnum.hasMoreElements()) {
      String varName = (String)varNamesEnum.nextElement();
      Nodo node = bayesianNetwork.getNodo(varName);
      Point position = new Point(node.getPosX(), node.getPosY());
      netView.insertVertex(varName, position);

    }

    varNamesEnum = bayesianNetwork.ListaVariables().elements();
    while (varNamesEnum.hasMoreElements()) {
      String varName = (String)varNamesEnum.nextElement();
      Nodo node = bayesianNetwork.getNodo(varName);
      Enumeration enum1 = node.getPadres().elements();
      while (enum1.hasMoreElements()) {
        Nodo item = (Nodo)enum1.nextElement();
        String parentName = bayesianNetwork.NombreExt(item);
        netView.connect(parentName, varName);
      }
    }
    changed = false;
  }

  /**
   * Saves the contained Bayesian Network to the current file
   */
  public boolean save() {
    if (fileName!=null && !fileName.equals("")) {
      bayesianNetwork.saveToFileXMLBIF(fileName);
      changed = false;
      mainFrame.someChange();
      return true;
    }
    else
      return saveAs();
  }

  /**
   * Prompts the user with a Save Dialog, saves the contained Bayesian
   * Network to the selected file and sets the current file to it.
   */
  public boolean saveAs() {
    JFileChooser chooser;
    String currDir = mainFrame.getCurrDir();
    if (currDir==null)
      chooser = new JFileChooser();
    else
      chooser = new JFileChooser(currDir);
    chooser.setFileFilter(new BifFilter());
    chooser.setDialogTitle(bayesianNetwork.getNombre() + " - Save as...");
    int returnVal = chooser.showSaveDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      currDir = chooser.getCurrentDirectory().getPath();
      mainFrame.setCurrDir(currDir);
      fileName = chooser.getSelectedFile().getPath();
      String ext =
          fileName.substring(fileName.lastIndexOf('.')+1).toLowerCase();
      if (!ext.equals("xml03"))
        fileName += ".xml03";
      bayesianNetwork.saveToFileXMLBIF(fileName);
      changed = false;
      mainFrame.someChange();
      return true;
    }
    return false;
  }


  /**
   * User confirmed frame close operation with save option
   */
  public boolean close() {
    if (changed) {
      int option = JOptionPane.showConfirmDialog(this,
                                                 bayesianNetwork.getNombre() +
                                                 " has not been saved. Save it now?",
                                                 "Save Network",
                                                 JOptionPane.YES_NO_CANCEL_OPTION,
                                                 JOptionPane.QUESTION_MESSAGE);
      switch (option) {
        case JOptionPane.OK_OPTION:
          if (!this.save())
            return false;
          break;
        case JOptionPane.CANCEL_OPTION:
          return false;
        case JOptionPane.CLOSED_OPTION:
          return false;
      }
    }
    bayesianNetwork.deleteObserver(this);
    dispose();
    mainFrame.someChange();
    return true;
  }

  /**
   * Gets the frame's current mode
   * @return int - the mode (either MODE_SELECT, MODE_NODE or MODE_ARC)
   */
  public int getMode() {
    return mode;
  }

  /**
   * Sets the mode for the frame
   * @param mode int - the new mode to be set
   */
  public void setMode(int mode) {
    this.mode = mode;
  }

  /**
   * Resets the frame's mode to default
   */
  public void resetMode() {
    this.mode = MODE_SELECT;
    buttonSelect.setSelected(true);
  }

  /**
   * Update method implicitly called by the Bayesian Network
   *
   * @param o Observable
   * @param arg Object
   */
  public void update(Observable o, Object arg) {
    this.setTitle(bayesianNetwork.getNombre());
    changed = true;
    mainFrame.someChange();
  }



  /**
   * Gets the current changed status
   * @return boolean
   */
  public boolean isChanged() {
    return changed;
  }

  void this_internalFrameActivated(InternalFrameEvent e) {
    mainFrame.someChange();
  }

  /**
   * Shows a properties dialog for this frame's bayesian network
   */
  void showBNPropertiesDialog() {
    String newName =
        (String) JOptionPane.showInputDialog(this,
                                             "Enter a new name:",
                                             "Properties",
                                             JOptionPane.PLAIN_MESSAGE,
                                             null,
                                             null,
                                             bayesianNetwork.getNombre());
    if (newName != null && !newName.equals("")) {
      bayesianNetwork.setNombre(newName);
      mainFrame().setStatus("Bayesian network renamed to \"" + newName + "\".");
    }
  }

  /**
   * Change to Editor type or Run type
   * @param e
   */
  void buttonRun_itemStateChanged(ItemEvent e) {

    switch (e.getStateChange()) {
      case ItemEvent.SELECTED:
        itemRun_Selected();
        break;
      case ItemEvent.DESELECTED:
        itemEdit_Selected();
        break;
    }
  }

  /**
   * Makes the changes for Run type
   */
  protected void itemRun_Selected(){
    toggleNodeProperties.setEnabled(false);
    buttonAddExpTable.setEnabled(false);
    buttonDelExpTable.setEnabled(false);
    setEnabledButtons(false);
    runPanel.SetComponents();
    runPanel.setVisible(true);
    setVisibleRun(true);
    buttonPropSumNormal.setSelected(true);

    mainFrame.jMenuFileSave.setEnabled(false);
    mainFrame.buttonSave.setEnabled(false);
    mainFrame.setStatus("");
  }

  /**
   * Makes the changes for Edit type
   */
  protected void itemEdit_Selected(){
    toggleNodeProperties.setEnabled(true);
    buttonAddExpTable.setEnabled(true);
    buttonDelExpTable.setEnabled(true);
    setEnabledButtons(true);
    runPanel.setVisible(false);
    setVisibleRun(false);
    runPanel.removeComponents();
    netView.changeToDefaultView();
    normalizarProb();

    mainFrame.jMenuFileSave.setEnabled(true);
    mainFrame.buttonSave.setEnabled(true);
    mainFrame.setStatus("");
 }

 /**
  * Sets buttons to be visible or not
  * @param state boolean - the new state of buttons
  */

 protected void setVisibleRun(boolean state){
    buttonInicNet.setVisible(state);
    buttonPropSumNormal.setVisible(state);
    buttonPropMaxNormal.setVisible(state);
    buttonPropSumRetract.setVisible(state);
    buttonPropMaxRetract.setVisible(state);
    buttonAdaptation.setVisible(state);
    buttonMonitor.setVisible(state);

  }

  /**
   * Sets buttons to be enabled or not
   * @param state boolean - the new state of buttons
   */
  protected void setEnabledButtons(boolean state){
    buttonCreateVar.setEnabled(state);
    buttonCreateLink.setEnabled(state);
    buttonDelete.setEnabled(state);
  }

  /**
   * Shows the table (Experience table or Potencial table) of the current node
   * if the button is selected.
   * @param e
   */
  protected void toggleNodeProperties_itemStateChanged(ItemEvent e) {

    switch (e.getStateChange()) {
      case ItemEvent.SELECTED:
        itemNodeProperties_Selected();
        break;
      case ItemEvent.DESELECTED:
        setEnabledButtons(true);
        tablesPanel.setVisible(false);
        buttonRun.setEnabled(true);
        break;
    }
  }

  /**
   * Shows Potencial tables or Experience tables
   * and sets some buttons to be enabled or not
   */
  protected void itemNodeProperties_Selected(){
      setEnabledButtons(false);
      buttonRun.setEnabled(false);
      tablesPanel.setVisible(true);
  }

  public RedBayes getBayesianNetwork(){
    return bayesianNetwork;
  }

  /**
   * Changes the panel to show experience tables or potencial tables
   */
  protected void setShowTable(){

    cardManager.show(tablesPanel, ""+mainFrame.getTable());
    if (selected instanceof String)
      ((Actualizable)tablesPanel.getComponent(mainFrame.getTable())).setCurrentNode((String) selected);
    else
          ((Actualizable)tablesPanel.getComponent(mainFrame.getTable())).setCurrentNode(null);

  }


  /**
   * This method is called every time the node selection changes so the
   * node properties toolbar can be updated
   * @param node Nodo - the new selected node
   */

  public void newNodeSelection(String varName) {
   mainFrame.setStatus("Variable " + varName + " selected.");
   ((Actualizable)tablesPanel.getComponent(mainFrame.getTable())).setCurrentNode((String) varName);
   if (this.isEditorType())
      buttonDelete.setEnabled(true);
      else{
        runPanel.jVar.setSelectedItem(varName);
        runPanel.jVarChanged(varName);
      }
   selected = varName;

 }

  /**
   * This method is called every time an edge is selected
   * @param edge DefaultEdge - the selected edge
   */
  public void newEdgeSelection(Link link) {
    mainFrame.setStatus("Link " + link + " selected.");
   ((Actualizable)tablesPanel.getComponent(mainFrame.getTable())).setCurrentNode(null);

   buttonDelete.setEnabled(true);
   buttonAdaptation.setEnabled(false);
   selected = link;
  }

  /**
   * This method is called every time the selection is cleared
   */
  public void nullSelection() {
    mainFrame.setStatus("Selection cleared");
    ((Actualizable)tablesPanel.getComponent(mainFrame.getTable())).setCurrentNode(null);

    buttonDelete.setEnabled(false);
    buttonAdaptation.setEnabled(false);
    selected = null;
  }

  /**
   * Renames a variable in the frame's bayesian network
   * @param oldName String - the old name of the variable
   * @param newName String - the new name
   */
  public void renameVar(String oldName, String newName) {
    if (bayesianNetwork.setNuevoNombre(oldName, newName)) {
      netView.renameVar(oldName, newName);
      nodePropertiesPanel.setCurrentNode(newName);
      if (selected!=null && ((String)selected).equals(oldName))
        selected=newName;
      mainFrame.setStatus("Variable " + oldName + " renamed to "
                          + newName + ".");
    }
  }


  /**
   * buttonDeleteClicked
   */
  public void buttonDeleteClicked() {
    if (selected != null) {
      if (selected instanceof String) {
        String varName = (String) selected;
        netView.deleteVar(varName);

      }
      else if (selected instanceof Link) {
        Link link = (Link) selected;
        String sourceName = bayesianNetwork.NombreExt(link.source);
        String targetName = bayesianNetwork.NombreExt(link.target);
        netView.deleteLink(sourceName, targetName);
      }
    }
  }

  public boolean isEditorType(){
    return !this.runPanel.isVisible();
  }

  public void netHasChanged(){
    changed=true;
  }

  public BNEditMainFrame mainFrame(){
    return this.mainFrame;
  }

  public Object selected(){
    return selected;
  }

  /**
   * Initiates the net
   * @param e
   */
  public void reinicializar() {
    runPanel.reinicializarRed();
    buttonPropSumNormal.setSelected(true);
  }

  public void propSumNormal() {
    propagate("obj17.ViewSumNormal","Sum Propagate: P(All)=");
  }

  public void propMaxNormal() {
    propagate("obj17.ViewMaxNormal","Sum Max Propagate: P(All)=");
  }

  public void propSumRetract()  {
    propagate("obj17.ViewSumRetracted","Sum Fast Retracted Propagate: P(All)=");
  }

  public void propMaxRetract() {
    propagate ("obj17.ViewMaxRetracted","Sum Max Fast Retracted Propagate: P(All)=");
  }

  public void propagate(String nameClass, String text){
    runPanel.showForm(nameClass);
    runPanel.setText(text);
  }

  public void addExpTable() {
    if (selected != null && selected instanceof String) {
      createExperienceTable((String) selected);
    }
  }

  /**
   * Creates an experience table to the node, if it hasn't got one.
   * @param varName String - the varible name
   */
  public void createExperienceTable(String varName){
    if (!bayesianNetwork.getNodo( varName).hasExperienceTable()) {
     changed=true;
     bayesianNetwork.getNodo( varName).addExperienceTable();
     mainFrame.setStatus("Variable " + varName +" added an Experience Table.");
     experienceTable.setCurrentNode( varName);
    }
  }

  /**
   * Deletes selected node's experience table
   */
  public void delExpTable() {
    if (selected != null && selected instanceof String) {
      if (bayesianNetwork.getNodo( (String) selected).hasExperienceTable()) {
        changed=true;
        bayesianNetwork.getNodo( (String) selected).delExperienceTable();
        experienceTable.setCurrentNode(null);
        mainFrame.setStatus("Variable " + (String) selected +
                            " deleted the Experience Table.");
      }
    }
  }

  public void adaptation (){

   String var=(String)runPanel.jVar.getSelectedItem();
//   String est=(String) runPanel.jEstado.getSelectedItem();
   Nodo act=bayesianNetwork.getNodo(var);
   if (act.hasExperienceTable()){
      changed=true;
      experienceTable.update(var);
      mainFrame.setStatus("Adaptation Completed");
   }
   else
     mainFrame.setStatus("Variable hasn't got an experience table");
 }

  private void normalizarProb(){
    for (Enumeration e=bayesianNetwork.ListaNodos().elements();e.hasMoreElements();){
      Nodo act=(Nodo) e.nextElement();
      if (act.hasExperienceTable())
        act.getProbabilidadOriginal().normalizar();
    }

  }

  public void setMonitorView() {
    if (selected != null) {
      if (selected instanceof String) {
        String varName = (String) selected;
        netView.changeToMonitor(varName);
      }
    }
  }

  public NetView getNetView(){
    return netView;

  }

}



class BNEditInternalFrame_this_internalFrameAdapter extends javax.swing.event.InternalFrameAdapter {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_this_internalFrameAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void internalFrameClosing(InternalFrameEvent e) {
    adaptee.close();
  }
  public void internalFrameActivated(InternalFrameEvent e) {
    adaptee.this_internalFrameActivated(e);
  }
}

class BNEditInternalFrame_buttonSelect_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonSelect_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.setMode(BNEditInternalFrame.MODE_SELECT);
  }
}

class BNEditInternalFrame_buttonCreateVar_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonCreateVar_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.setMode(BNEditInternalFrame.MODE_NODE);
  }
}

class BNEditInternalFrame_buttonCreateLink_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonCreateLink_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.setMode(BNEditInternalFrame.MODE_ARC);
  }
}

class BNEditInternalFrame_buttonNetworkProperties_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonNetworkProperties_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.showBNPropertiesDialog();
  }
}


class BNEditInternalFrame_buttonRun_itemAdapter implements java.awt.event.ItemListener {
BNEditInternalFrame adaptee;

BNEditInternalFrame_buttonRun_itemAdapter(BNEditInternalFrame adaptee) {
  this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent e) {
  adaptee.buttonRun_itemStateChanged(e);
}
}



class BNEditInternalFrame_toggleNodeProperties_itemAdapter implements java.awt.event.ItemListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_toggleNodeProperties_itemAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void itemStateChanged(ItemEvent e) {
    adaptee.toggleNodeProperties_itemStateChanged(e);
  }
}

class BNEditInternalFrame_buttonDelete_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonDelete_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.buttonDeleteClicked();
  }
}

class BNEditInternalFrame_buttonInicNet_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonInicNet_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
     adaptee.reinicializar();
  }
}

class BNEditInternalFrame_buttonPropSumNormal_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonPropSumNormal_actionAdapter(BNEditInternalFrame adaptee){
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
      adaptee.propSumNormal();
  }
}

class BNEditInternalFrame_buttonPropMaxNormal_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonPropMaxNormal_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
      adaptee.propMaxNormal();
  }
}

class BNEditInternalFrame_buttonPropSumRetract_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonPropSumRetract_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
      adaptee.propSumRetract();
  }
}

class BNEditInternalFrame_buttonPropMaxRetract_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonPropMaxRetract_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
      adaptee.propMaxRetract();
  }
}


class BNEditInternalFrame_buttonAddExpTable_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonAddExpTable_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.addExpTable();
  }
}

class BNEditInternalFrame_buttonAdaptation_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonAdaptation_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.adaptation();
  }
}

class BNEditInternalFrame_buttonMonitor_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonMonitor_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.setMonitorView();
  }
}

class BNEditInternalFrame_buttonDelExpTable_actionAdapter implements java.awt.event.ActionListener {
  BNEditInternalFrame adaptee;

  BNEditInternalFrame_buttonDelExpTable_actionAdapter(BNEditInternalFrame adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.delExpTable();
  }
}

